package com.ian.tag.linked;

import com.ian.linked.ListNode;

import java.util.LinkedList;

/**
 * @author zhangyaowen
 * @date 2021/2/22 10:28 下午
 */
public class IsPalindrome {

    public boolean isPalindrome(ListNode head) {

        LinkedList<Integer> linkedList = new LinkedList();

        if (head ==null || head.next ==null)
            return  true;

        while(head != null){

            linkedList.push(head.val);
            head = head.next;
        }


        while(!linkedList.isEmpty()){
          int a =  linkedList.pollFirst();

          if (linkedList.isEmpty()){
              return  false;
          }
          int b =   linkedList.pollLast();

           if (a != b){
               return  false;
           }
        }
        return true;
    }
}
